<!--
 * @Author: coman
 * @LastEditors: coman
 * @Date: 2020-06-16 21:01:28
 * @motto: No pain,No gain
 * @LastEditTime: 2020-06-17 10:07:37
--> 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{margin: 0;padding: 0;}
        table{
            border-collapse: collapse;
            border-spacing: 0;
        }
        th,tr,td{
            width: 200px;
            height: 100px;
            border: 1px solid red;
            text-align: center;
            line-height: 100px;
        }
    </style>
</head>
<body>
    <!-- 以下是某班级一次考试的成绩表。请计算每个学生总成绩，并按总成绩排名。统
计各单科成绩第一名，输出其成绩与学号。 -->
<table id="tb">
    <th>学号</th>
    <th>姓名</th>
    <th>语文</th>
    <th>数学</th>
    <th>英语</th>
    <th>总成绩</th>
    <th>备注</th>
    
</table>
     <script>
         //存放总成绩
     var stu = [
                {xuehao:1,name:'zhangsan',chinese:105,math:62,english:118},
                {xuehao:2,name:'lisi',chinese:89,math:78,english:120},
                {xuehao:3,name:'xixi',chinese:86,math:64,english:80},
                {xuehao:4,name:'Amy',chinese:78,math:99,english:91},
                {xuehao:5,name:'John',chinese:107.5,math:97,english:70},
                {xuehao:6,name:'Alan',chinese:112,math:61,english:92},
                {xuehao:7,name:'James',chinese:101,math:79,english:104},
                {xuehao:8,name:'messi',chinese:71,math:72,english:105},
                {xuehao:9,name:'ronaldo',chinese:56,math:68,english:61},
                {xuehao:10,name:'pogba',chinese:98,math:83,english:77},
            ]
            //获得对象长度
            
        for(var i=0;i<stu.length;i++){
            stu[i].total=stu[i].chinese+stu[i].english+stu[i].math;
        }
        //冒泡排序
      for(var i=0;i<stu.length;i++){
          for(var j=0;j<stu.length-i-1;j++){
            if(stu[j].total<stu[j+1].total){
                var temp = stu[j];
                stu[j] = stu[j+1];
                stu[j+1]=temp;
            }
          }
      }
      //语文成绩最高
      var min=0;
     for(var i=1;i<stu.length;i++){
        
        if(stu[min].chinese<stu[i].chinese){
            min=i;
        }   
     }
    stu[min].detail="语文成绩最高";
           //数学成绩最高
      var min=0;
     for(var i=1;i<stu.length;i++){
        
        if(stu[min].math<stu[i].math){
            min=i;
        }   
     }
     stu[min].detail="数学成绩最高";

    //英语成绩最高
    var min=0;
        for(var i=1;i<stu.length;i++){
            
            if(stu[min].english<stu[i].english){
                min=i;
            }   
        }
        
        stu[min].detail="英语成绩最高";
        console.log(stu);
        for(var i=0;i<stu.length;i++){
            if(!stu[i].detail){stu[i].detail=""}
        tb.innerHTML+="<tr>"+"<td>"+stu[i].xuehao+"</td>"+"<td>"+stu[i].name+"</td>"+"<td>"+stu[i].chinese
        +"</td>"+"<td>"+stu[i].math+"</td>"+"<td>"+stu[i].english+"</td>"+"<td>"+stu[i].total+"</td>"+"<td>"+stu[i].detail+"</td>"+"</tr>"
        }
        </script>
    
</body>
</html>